﻿///////////////////////////////////////////////////////////////
// This is generated code. 
//////////////////////////////////////////////////////////////
// Code is generated using LLBLGen Pro version: 2.6
// Code is generated on: Tuesday, June 23, 2009 10:22:09 PM
// Code is generated using templates: SD.TemplateBindings.SharedTemplates.NET20
// Templates vendor: Solutions Design.
// Templates version: 
//////////////////////////////////////////////////////////////
using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Collections;
#if !CF
using System.Runtime.Serialization;
#endif
using System.Data;
using System.Xml.Serialization;
using OrmSmackdown.LLBLGen;
using OrmSmackdown.LLBLGen.FactoryClasses;
using OrmSmackdown.LLBLGen.DaoClasses;
using OrmSmackdown.LLBLGen.RelationClasses;
using OrmSmackdown.LLBLGen.HelperClasses;
using OrmSmackdown.LLBLGen.CollectionClasses;

using SD.LLBLGen.Pro.ORMSupportClasses;

namespace OrmSmackdown.LLBLGen.EntityClasses
{
	
	// __LLBLGENPRO_USER_CODE_REGION_START AdditionalNamespaces
	// __LLBLGENPRO_USER_CODE_REGION_END

	/// <summary>
	/// Entity class which represents the entity 'People'. <br/><br/>
	/// 
	/// </summary>
	[Serializable]
	public partial class PeopleEntity : CommonEntityBase, ISerializable
		// __LLBLGENPRO_USER_CODE_REGION_START AdditionalInterfaces
		// __LLBLGENPRO_USER_CODE_REGION_END	
	{
		#region Class Member Declarations
		private OrmSmackdown.LLBLGen.CollectionClasses.AddressesCollection	_addresses;
		private bool	_alwaysFetchAddresses, _alreadyFetchedAddresses;
		private OrmSmackdown.LLBLGen.CollectionClasses.PeopleCollection	_manager;
		private bool	_alwaysFetchManager, _alreadyFetchedManager;

		private OrmSmackdown.LLBLGen.CollectionClasses.PortalsCollection	_administeredPortals;
		private bool	_alwaysFetchAdministeredPortals, _alreadyFetchedAdministeredPortals;

		private OrmSmackdown.LLBLGen.CollectionClasses.PortalsCollection _myPortals;
		private bool	_alwaysFetchMyPortals, _alreadyFetchedMyPortals;

		private CompaniesEntity _company;
		private bool	_alwaysFetchCompany, _alreadyFetchedCompany, _companyReturnsNewIfNotFound;
		private PeopleEntity _employees;
		private bool	_alwaysFetchEmployees, _alreadyFetchedEmployees, _employeesReturnsNewIfNotFound;
		private RolesEntity _myRole;
		private bool	_alwaysFetchMyRole, _alreadyFetchedMyRole, _myRoleReturnsNewIfNotFound;

		
		// __LLBLGENPRO_USER_CODE_REGION_START PrivateMembers
		// __LLBLGENPRO_USER_CODE_REGION_END
		#endregion

		#region Statics
		private static Dictionary<string, string>	_customProperties;
		private static Dictionary<string, Dictionary<string, string>>	_fieldsCustomProperties;

		/// <summary>All names of fields mapped onto a relation. Usable for in-memory filtering</summary>
		public static partial class MemberNames
		{
			/// <summary>Member name Company</summary>
			public static readonly string Company = "Company";
			/// <summary>Member name Employees</summary>
			public static readonly string Employees = "Employees";
			/// <summary>Member name MyRole</summary>
			public static readonly string MyRole = "MyRole";
			/// <summary>Member name Addresses</summary>
			public static readonly string Addresses = "Addresses";
			/// <summary>Member name Manager</summary>
			public static readonly string Manager = "Manager";

			/// <summary>Member name AdministeredPortals</summary>
			public static readonly string AdministeredPortals = "AdministeredPortals";

			/// <summary>Member name MyPortals</summary>
			public static readonly string MyPortals = "MyPortals";


		}
		#endregion
		
		/// <summary>Static CTor for setting up custom property hashtables. Is executed before the first instance of this entity class or derived classes is constructed. </summary>
		static PeopleEntity()
		{
			SetupCustomPropertyHashtables();
		}

		/// <summary>CTor</summary>
		public PeopleEntity()
		{
			InitClassEmpty(null);
		}


		/// <summary>CTor</summary>
		/// <param name="personId">PK value for People which data should be fetched into this People object</param>
		public PeopleEntity(System.Int32 personId)
		{
			InitClassFetch(personId, null, null);
		}

		/// <summary>CTor</summary>
		/// <param name="personId">PK value for People which data should be fetched into this People object</param>
		/// <param name="prefetchPathToUse">the PrefetchPath which defines the graph of objects to fetch as well</param>
		public PeopleEntity(System.Int32 personId, IPrefetchPath prefetchPathToUse)
		{
			InitClassFetch(personId, null, prefetchPathToUse);
		}

		/// <summary>CTor</summary>
		/// <param name="personId">PK value for People which data should be fetched into this People object</param>
		/// <param name="validator">The custom validator object for this PeopleEntity</param>
		public PeopleEntity(System.Int32 personId, IValidator validator)
		{
			InitClassFetch(personId, validator, null);
		}


		/// <summary>Private CTor for deserialization</summary>
		/// <param name="info"></param>
		/// <param name="context"></param>
		protected PeopleEntity(SerializationInfo info, StreamingContext context) : base(info, context)
		{
			_addresses = (OrmSmackdown.LLBLGen.CollectionClasses.AddressesCollection)info.GetValue("_addresses", typeof(OrmSmackdown.LLBLGen.CollectionClasses.AddressesCollection));
			_alwaysFetchAddresses = info.GetBoolean("_alwaysFetchAddresses");
			_alreadyFetchedAddresses = info.GetBoolean("_alreadyFetchedAddresses");
			_manager = (OrmSmackdown.LLBLGen.CollectionClasses.PeopleCollection)info.GetValue("_manager", typeof(OrmSmackdown.LLBLGen.CollectionClasses.PeopleCollection));
			_alwaysFetchManager = info.GetBoolean("_alwaysFetchManager");
			_alreadyFetchedManager = info.GetBoolean("_alreadyFetchedManager");

			_administeredPortals = (OrmSmackdown.LLBLGen.CollectionClasses.PortalsCollection)info.GetValue("_administeredPortals", typeof(OrmSmackdown.LLBLGen.CollectionClasses.PortalsCollection));
			_alwaysFetchAdministeredPortals = info.GetBoolean("_alwaysFetchAdministeredPortals");
			_alreadyFetchedAdministeredPortals = info.GetBoolean("_alreadyFetchedAdministeredPortals");

			_myPortals = (OrmSmackdown.LLBLGen.CollectionClasses.PortalsCollection)info.GetValue("_myPortals", typeof(OrmSmackdown.LLBLGen.CollectionClasses.PortalsCollection));
			_alwaysFetchMyPortals = info.GetBoolean("_alwaysFetchMyPortals");
			_alreadyFetchedMyPortals = info.GetBoolean("_alreadyFetchedMyPortals");

			_company = (CompaniesEntity)info.GetValue("_company", typeof(CompaniesEntity));
			if(_company!=null)
			{
				_company.AfterSave+=new EventHandler(OnEntityAfterSave);
			}
			_companyReturnsNewIfNotFound = info.GetBoolean("_companyReturnsNewIfNotFound");
			_alwaysFetchCompany = info.GetBoolean("_alwaysFetchCompany");
			_alreadyFetchedCompany = info.GetBoolean("_alreadyFetchedCompany");
			_employees = (PeopleEntity)info.GetValue("_employees", typeof(PeopleEntity));
			if(_employees!=null)
			{
				_employees.AfterSave+=new EventHandler(OnEntityAfterSave);
			}
			_employeesReturnsNewIfNotFound = info.GetBoolean("_employeesReturnsNewIfNotFound");
			_alwaysFetchEmployees = info.GetBoolean("_alwaysFetchEmployees");
			_alreadyFetchedEmployees = info.GetBoolean("_alreadyFetchedEmployees");
			_myRole = (RolesEntity)info.GetValue("_myRole", typeof(RolesEntity));
			if(_myRole!=null)
			{
				_myRole.AfterSave+=new EventHandler(OnEntityAfterSave);
			}
			_myRoleReturnsNewIfNotFound = info.GetBoolean("_myRoleReturnsNewIfNotFound");
			_alwaysFetchMyRole = info.GetBoolean("_alwaysFetchMyRole");
			_alreadyFetchedMyRole = info.GetBoolean("_alreadyFetchedMyRole");

			base.FixupDeserialization(FieldInfoProviderSingleton.GetInstance(), PersistenceInfoProviderSingleton.GetInstance());
			
			// __LLBLGENPRO_USER_CODE_REGION_START DeserializationConstructor
			// __LLBLGENPRO_USER_CODE_REGION_END
		}

		
		/// <summary>Performs the desync setup when an FK field has been changed. The entity referenced based on the FK field will be dereferenced and sync info will be removed.</summary>
		/// <param name="fieldIndex">The fieldindex.</param>
		protected override void PerformDesyncSetupFKFieldChange(int fieldIndex)
		{
			switch((PeopleFieldIndex)fieldIndex)
			{
				case PeopleFieldIndex.CompanyId:
					DesetupSyncCompany(true, false);
					_alreadyFetchedCompany = false;
					break;
				case PeopleFieldIndex.RoleId:
					DesetupSyncMyRole(true, false);
					_alreadyFetchedMyRole = false;
					break;
				case PeopleFieldIndex.ManagerPersonId:
					DesetupSyncEmployees(true, false);
					_alreadyFetchedEmployees = false;
					break;
				default:
					base.PerformDesyncSetupFKFieldChange(fieldIndex);
					break;
			}
		}
		
		/// <summary>Gets the inheritance info provider instance of the project this entity instance is located in. </summary>
		/// <returns>ready to use inheritance info provider instance.</returns>
		protected override IInheritanceInfoProvider GetInheritanceInfoProvider()
		{
			return InheritanceInfoProviderSingleton.GetInstance();
		}
		
		/// <summary> Will perform post-ReadXml actions</summary>
		protected override void PostReadXmlFixups()
		{
			_alreadyFetchedAddresses = (_addresses.Count > 0);
			_alreadyFetchedManager = (_manager.Count > 0);

			_alreadyFetchedAdministeredPortals = (_administeredPortals.Count > 0);

			_alreadyFetchedMyPortals = (_myPortals.Count > 0);

			_alreadyFetchedCompany = (_company != null);
			_alreadyFetchedEmployees = (_employees != null);
			_alreadyFetchedMyRole = (_myRole != null);

		}
				
		/// <summary>Gets the relation objects which represent the relation the fieldName specified is mapped on. </summary>
		/// <param name="fieldName">Name of the field mapped onto the relation of which the relation objects have to be obtained.</param>
		/// <returns>RelationCollection with relation object(s) which represent the relation the field is maped on</returns>
		public override RelationCollection GetRelationsForFieldOfType(string fieldName)
		{
			return PeopleEntity.GetRelationsForField(fieldName);
		}

		/// <summary>Gets the relation objects which represent the relation the fieldName specified is mapped on. </summary>
		/// <param name="fieldName">Name of the field mapped onto the relation of which the relation objects have to be obtained.</param>
		/// <returns>RelationCollection with relation object(s) which represent the relation the field is maped on</returns>
		public static RelationCollection GetRelationsForField(string fieldName)
		{
			RelationCollection toReturn = new RelationCollection();
			switch(fieldName)
			{
				case "Company":
					toReturn.Add(PeopleEntity.Relations.CompaniesEntityUsingCompanyId);
					break;
				case "Employees":
					toReturn.Add(PeopleEntity.Relations.PeopleEntityUsingPersonIdManagerPersonId);
					break;
				case "MyRole":
					toReturn.Add(PeopleEntity.Relations.RolesEntityUsingRoleId);
					break;
				case "Addresses":
					toReturn.Add(PeopleEntity.Relations.AddressesEntityUsingPersonId);
					break;
				case "Manager":
					toReturn.Add(PeopleEntity.Relations.PeopleEntityUsingManagerPersonId);
					break;

				case "AdministeredPortals":
					toReturn.Add(PeopleEntity.Relations.PortalsEntityUsingAdminUserId);
					break;

				case "MyPortals":
					toReturn.Add(PeopleEntity.Relations.PortalPeopleXrefEntityUsingPersonId, "PeopleEntity__", "PortalPeopleXref_", JoinHint.None);
					toReturn.Add(PortalPeopleXrefEntity.Relations.PortalsEntityUsingPortalId, "PortalPeopleXref_", string.Empty, JoinHint.None);
					break;


				default:

					break;				
			}
			return toReturn;
		}

		/// <summary> Gets the inheritance info for this entity, if applicable (it's then overriden) or null if not.</summary>
		/// <returns>InheritanceInfo object if this entity is in a hierarchy of type TargetPerEntity, or null otherwise</returns>
		[EditorBrowsable(EditorBrowsableState.Never)]
		public override IInheritanceInfo GetInheritanceInfo()
		{
			return InheritanceInfoProviderSingleton.GetInstance().GetInheritanceInfo("PeopleEntity", false);
		}
		
		/// <summary>Gets a predicateexpression which filters on this entity</summary>
		/// <returns>ready to use predicateexpression</returns>
		/// <remarks>Only useful in entity fetches.</remarks>
		public  static IPredicateExpression GetEntityTypeFilter()
		{
			return InheritanceInfoProviderSingleton.GetInstance().GetEntityTypeFilter("PeopleEntity", false);
		}
		
		/// <summary>Gets a predicateexpression which filters on this entity</summary>
		/// <param name="negate">Flag to produce a NOT filter, (true), or a normal filter (false). </param>
		/// <returns>ready to use predicateexpression</returns>
		/// <remarks>Only useful in entity fetches.</remarks>
		public  static IPredicateExpression GetEntityTypeFilter(bool negate)
		{
			return InheritanceInfoProviderSingleton.GetInstance().GetEntityTypeFilter("PeopleEntity", negate);
		}

		/// <summary> ISerializable member. Does custom serialization so event handlers do not get serialized.
		/// Serializes members of this entity class and uses the base class' implementation to serialize the rest.</summary>
		/// <param name="info"></param>
		/// <param name="context"></param>
		[EditorBrowsable(EditorBrowsableState.Never)]
		public override void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			info.AddValue("_addresses", (!this.MarkedForDeletion?_addresses:null));
			info.AddValue("_alwaysFetchAddresses", _alwaysFetchAddresses);
			info.AddValue("_alreadyFetchedAddresses", _alreadyFetchedAddresses);
			info.AddValue("_manager", (!this.MarkedForDeletion?_manager:null));
			info.AddValue("_alwaysFetchManager", _alwaysFetchManager);
			info.AddValue("_alreadyFetchedManager", _alreadyFetchedManager);

			info.AddValue("_administeredPortals", (!this.MarkedForDeletion?_administeredPortals:null));
			info.AddValue("_alwaysFetchAdministeredPortals", _alwaysFetchAdministeredPortals);
			info.AddValue("_alreadyFetchedAdministeredPortals", _alreadyFetchedAdministeredPortals);

			info.AddValue("_myPortals", (!this.MarkedForDeletion?_myPortals:null));
			info.AddValue("_alwaysFetchMyPortals", _alwaysFetchMyPortals);
			info.AddValue("_alreadyFetchedMyPortals", _alreadyFetchedMyPortals);

			info.AddValue("_company", (!this.MarkedForDeletion?_company:null));
			info.AddValue("_companyReturnsNewIfNotFound", _companyReturnsNewIfNotFound);
			info.AddValue("_alwaysFetchCompany", _alwaysFetchCompany);
			info.AddValue("_alreadyFetchedCompany", _alreadyFetchedCompany);
			info.AddValue("_employees", (!this.MarkedForDeletion?_employees:null));
			info.AddValue("_employeesReturnsNewIfNotFound", _employeesReturnsNewIfNotFound);
			info.AddValue("_alwaysFetchEmployees", _alwaysFetchEmployees);
			info.AddValue("_alreadyFetchedEmployees", _alreadyFetchedEmployees);
			info.AddValue("_myRole", (!this.MarkedForDeletion?_myRole:null));
			info.AddValue("_myRoleReturnsNewIfNotFound", _myRoleReturnsNewIfNotFound);
			info.AddValue("_alwaysFetchMyRole", _alwaysFetchMyRole);
			info.AddValue("_alreadyFetchedMyRole", _alreadyFetchedMyRole);

			
			// __LLBLGENPRO_USER_CODE_REGION_START GetObjectInfo
			// __LLBLGENPRO_USER_CODE_REGION_END
			base.GetObjectData(info, context);
		}
		
		/// <summary> Sets the related entity property to the entity specified. If the property is a collection, it will add the entity specified to that collection.</summary>
		/// <param name="propertyName">Name of the property.</param>
		/// <param name="entity">Entity to set as an related entity</param>
		/// <remarks>Used by prefetch path logic.</remarks>
		[EditorBrowsable(EditorBrowsableState.Never)]
		public override void SetRelatedEntityProperty(string propertyName, IEntity entity)
		{
			switch(propertyName)
			{
				case "Company":
					_alreadyFetchedCompany = true;
					this.Company = (CompaniesEntity)entity;
					break;
				case "Employees":
					_alreadyFetchedEmployees = true;
					this.Employees = (PeopleEntity)entity;
					break;
				case "MyRole":
					_alreadyFetchedMyRole = true;
					this.MyRole = (RolesEntity)entity;
					break;
				case "Addresses":
					_alreadyFetchedAddresses = true;
					if(entity!=null)
					{
						this.Addresses.Add((AddressesEntity)entity);
					}
					break;
				case "Manager":
					_alreadyFetchedManager = true;
					if(entity!=null)
					{
						this.Manager.Add((PeopleEntity)entity);
					}
					break;

				case "AdministeredPortals":
					_alreadyFetchedAdministeredPortals = true;
					if(entity!=null)
					{
						this.AdministeredPortals.Add((PortalsEntity)entity);
					}
					break;

				case "MyPortals":
					_alreadyFetchedMyPortals = true;
					if(entity!=null)
					{
						this.MyPortals.Add((PortalsEntity)entity);
					}
					break;


				default:

					break;
			}
		}

		/// <summary> Sets the internal parameter related to the fieldname passed to the instance relatedEntity. </summary>
		/// <param name="relatedEntity">Instance to set as the related entity of type entityType</param>
		/// <param name="fieldName">Name of field mapped onto the relation which resolves in the instance relatedEntity</param>
		[EditorBrowsable(EditorBrowsableState.Never)]
		public override void SetRelatedEntity(IEntity relatedEntity, string fieldName)
		{
			switch(fieldName)
			{
				case "Company":
					SetupSyncCompany(relatedEntity);
					break;
				case "Employees":
					SetupSyncEmployees(relatedEntity);
					break;
				case "MyRole":
					SetupSyncMyRole(relatedEntity);
					break;
				case "Addresses":
					_addresses.Add((AddressesEntity)relatedEntity);
					break;
				case "Manager":
					_manager.Add((PeopleEntity)relatedEntity);
					break;

				case "AdministeredPortals":
					_administeredPortals.Add((PortalsEntity)relatedEntity);
					break;

				default:

					break;
			}
		}
		
		/// <summary> Unsets the internal parameter related to the fieldname passed to the instance relatedEntity. Reverses the actions taken by SetRelatedEntity() </summary>
		/// <param name="relatedEntity">Instance to unset as the related entity of type entityType</param>
		/// <param name="fieldName">Name of field mapped onto the relation which resolves in the instance relatedEntity</param>
		/// <param name="signalRelatedEntityManyToOne">if set to true it will notify the manytoone side, if applicable.</param>
		[EditorBrowsable(EditorBrowsableState.Never)]
		public override void UnsetRelatedEntity(IEntity relatedEntity, string fieldName, bool signalRelatedEntityManyToOne)
		{
			switch(fieldName)
			{
				case "Company":
					DesetupSyncCompany(false, true);
					break;
				case "Employees":
					DesetupSyncEmployees(false, true);
					break;
				case "MyRole":
					DesetupSyncMyRole(false, true);
					break;
				case "Addresses":
					base.PerformRelatedEntityRemoval(_addresses, relatedEntity, signalRelatedEntityManyToOne);
					break;
				case "Manager":
					base.PerformRelatedEntityRemoval(_manager, relatedEntity, signalRelatedEntityManyToOne);
					break;

				case "AdministeredPortals":
					base.PerformRelatedEntityRemoval(_administeredPortals, relatedEntity, signalRelatedEntityManyToOne);
					break;

				default:

					break;
			}
		}

		/// <summary> Gets a collection of related entities referenced by this entity which depend on this entity (this entity is the PK side of their FK fields). These
		/// entities will have to be persisted after this entity during a recursive save.</summary>
		/// <returns>Collection with 0 or more IEntity objects, referenced by this entity</returns>
		public override List<IEntity> GetDependingRelatedEntities()
		{
			List<IEntity> toReturn = new List<IEntity>();


			return toReturn;
		}
		
		/// <summary> Gets a collection of related entities referenced by this entity which this entity depends on (this entity is the FK side of their PK fields). These
		/// entities will have to be persisted before this entity during a recursive save.</summary>
		/// <returns>Collection with 0 or more IEntity objects, referenced by this entity</returns>
		public override List<IEntity> GetDependentRelatedEntities()
		{
			List<IEntity> toReturn = new List<IEntity>();
			if(_company!=null)
			{
				toReturn.Add(_company);
			}
			if(_employees!=null)
			{
				toReturn.Add(_employees);
			}
			if(_myRole!=null)
			{
				toReturn.Add(_myRole);
			}


			return toReturn;
		}
		
		/// <summary> Gets a List of all entity collections stored as member variables in this entity. The contents of the ArrayList is
		/// used by the DataAccessAdapter to perform recursive saves. Only 1:n related collections are returned.</summary>
		/// <returns>Collection with 0 or more IEntityCollection objects, referenced by this entity</returns>
		public override List<IEntityCollection> GetMemberEntityCollections()
		{
			List<IEntityCollection> toReturn = new List<IEntityCollection>();
			toReturn.Add(_addresses);
			toReturn.Add(_manager);

			toReturn.Add(_administeredPortals);

			return toReturn;
		}

		

		/// <summary> Fetches the contents of this entity from the persistent storage using the primary key specified in a polymorphic way, so the entity returned 
		/// could be of a subtype of the current entity or the current entity.</summary>
		/// <param name="transactionToUse">transaction to use during fetch</param>
		/// <param name="personId">PK value for People which data should be fetched into this People object</param>
		/// <param name="contextToUse">Context to use for fetch</param>
		/// <returns>Fetched entity of the type of this entity or a subtype, or an empty entity of that type if not found.</returns>
		/// <remarks>Creates a new instance, doesn't fill <i>this</i> entity instance</remarks>
		public static  PeopleEntity FetchPolymorphic(ITransaction transactionToUse, System.Int32 personId, Context contextToUse)
		{
			return FetchPolymorphic(transactionToUse, personId, contextToUse, null);
		}
				
		/// <summary> Fetches the contents of this entity from the persistent storage using the primary key specified in a polymorphic way, so the entity returned 
		/// could be of a subtype of the current entity or the current entity.</summary>
		/// <param name="transactionToUse">transaction to use during fetch</param>
		/// <param name="personId">PK value for People which data should be fetched into this People object</param>
		/// <param name="contextToUse">Context to use for fetch</param>
		/// <param name="excludedIncludedFields">The list of IEntityField objects which have to be excluded or included for the fetch. 
		/// If null or empty, all fields are fetched (default). If an instance of ExcludeIncludeFieldsList is passed in and its ExcludeContainedFields property
		/// is set to false, the fields contained in excludedIncludedFields are kept in the query, the rest of the fields in the query are excluded.</param>
		/// <returns>Fetched entity of the type of this entity or a subtype, or an empty entity of that type if not found.</returns>
		/// <remarks>Creates a new instance, doesn't fill <i>this</i> entity instance</remarks>
		public static  PeopleEntity FetchPolymorphic(ITransaction transactionToUse, System.Int32 personId, Context contextToUse, ExcludeIncludeFieldsList excludedIncludedFields)
		{
			PeopleDAO dao = new PeopleDAO();
			IEntityFields fields = EntityFieldsFactory.CreateEntityFieldsObject(OrmSmackdown.LLBLGen.EntityType.PeopleEntity);
			fields[(int)PeopleFieldIndex.PersonId].ForcedCurrentValueWrite(personId);
			return (PeopleEntity)dao.FetchExistingPolymorphic(transactionToUse, fields, contextToUse, excludedIncludedFields);
		}
		

		/// <summary> Fetches the contents of this entity from the persistent storage using the primary key.</summary>
		/// <param name="personId">PK value for People which data should be fetched into this People object</param>
		/// <returns>True if succeeded, false otherwise.</returns>
		public bool FetchUsingPK(System.Int32 personId)
		{
			return FetchUsingPK(personId, null, null, null);
		}

		/// <summary> Fetches the contents of this entity from the persistent storage using the primary key.</summary>
		/// <param name="personId">PK value for People which data should be fetched into this People object</param>
		/// <param name="prefetchPathToUse">the PrefetchPath which defines the graph of objects to fetch as well</param>
		/// <returns>True if succeeded, false otherwise.</returns>
		public bool FetchUsingPK(System.Int32 personId, IPrefetchPath prefetchPathToUse)
		{
			return FetchUsingPK(personId, prefetchPathToUse, null, null);
		}

		/// <summary> Fetches the contents of this entity from the persistent storage using the primary key.</summary>
		/// <param name="personId">PK value for People which data should be fetched into this People object</param>
		/// <param name="prefetchPathToUse">the PrefetchPath which defines the graph of objects to fetch as well</param>
		/// <param name="contextToUse">The context to add the entity to if the fetch was succesful. </param>
		/// <returns>True if succeeded, false otherwise.</returns>
		public bool FetchUsingPK(System.Int32 personId, IPrefetchPath prefetchPathToUse, Context contextToUse)
		{
			return Fetch(personId, prefetchPathToUse, contextToUse, null);
		}

		/// <summary> Fetches the contents of this entity from the persistent storage using the primary key.</summary>
		/// <param name="personId">PK value for People which data should be fetched into this People object</param>
		/// <param name="prefetchPathToUse">the PrefetchPath which defines the graph of objects to fetch as well</param>
		/// <param name="contextToUse">The context to add the entity to if the fetch was succesful. </param>
		/// <param name="excludedIncludedFields">The list of IEntityField objects which have to be excluded or included for the fetch. 
		/// If null or empty, all fields are fetched (default). If an instance of ExcludeIncludeFieldsList is passed in and its ExcludeContainedFields property
		/// is set to false, the fields contained in excludedIncludedFields are kept in the query, the rest of the fields in the query are excluded.</param>
		/// <returns>True if succeeded, false otherwise.</returns>
		public bool FetchUsingPK(System.Int32 personId, IPrefetchPath prefetchPathToUse, Context contextToUse, ExcludeIncludeFieldsList excludedIncludedFields)
		{
			return Fetch(personId, prefetchPathToUse, contextToUse, excludedIncludedFields);
		}

		/// <summary> Refetches the Entity from the persistent storage. Refetch is used to re-load an Entity which is marked "Out-of-sync", due to a save action. 
		/// Refetching an empty Entity has no effect. </summary>
		/// <returns>true if Refetch succeeded, false otherwise</returns>
		public override bool Refetch()
		{
			return Fetch(this.PersonId, null, null, null);
		}

		/// <summary> Returns true if the original value for the field with the fieldIndex passed in, read from the persistent storage was NULL, false otherwise.
		/// Should not be used for testing if the current value is NULL, use <see cref="TestCurrentFieldValueForNull"/> for that.</summary>
		/// <param name="fieldIndex">Index of the field to test if that field was NULL in the persistent storage</param>
		/// <returns>true if the field with the passed in index was NULL in the persistent storage, false otherwise</returns>
		public bool TestOriginalFieldValueForNull(PeopleFieldIndex fieldIndex)
		{
			return base.Fields[(int)fieldIndex].IsNull;
		}
		
		/// <summary>Returns true if the current value for the field with the fieldIndex passed in represents null/not defined, false otherwise.
		/// Should not be used for testing if the original value (read from the db) is NULL</summary>
		/// <param name="fieldIndex">Index of the field to test if its currentvalue is null/undefined</param>
		/// <returns>true if the field's value isn't defined yet, false otherwise</returns>
		public bool TestCurrentFieldValueForNull(PeopleFieldIndex fieldIndex)
		{
			return base.CheckIfCurrentFieldValueIsNull((int)fieldIndex);
		}
		
		/// <summary>Determines whether this entity is a subType of the entity represented by the passed in enum value, which represents a value in the OrmSmackdown.LLBLGen.EntityType enum</summary>
		/// <param name="typeOfEntity">Type of entity.</param>
		/// <returns>true if the passed in type is a supertype of this entity, otherwise false</returns>
		[EditorBrowsable(EditorBrowsableState.Never)]
		public override bool CheckIfIsSubTypeOf(int typeOfEntity)
		{
			return InheritanceInfoProviderSingleton.GetInstance().CheckIfIsSubTypeOf("PeopleEntity", ((OrmSmackdown.LLBLGen.EntityType)typeOfEntity).ToString());
		}
				
		/// <summary>Gets a list of all the EntityRelation objects the type of this instance has.</summary>
		/// <returns>A list of all the EntityRelation objects the type of this instance has. Hierarchy relations are excluded.</returns>
		public override List<IEntityRelation> GetAllRelations()
		{
			return new PeopleRelations().GetAllRelations();
		}


		/// <summary> Retrieves all related entities of type 'AddressesEntity' using a relation of type '1:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <returns>Filled collection with all related entities of type 'AddressesEntity'</returns>
		public OrmSmackdown.LLBLGen.CollectionClasses.AddressesCollection GetMultiAddresses(bool forceFetch)
		{
			return GetMultiAddresses(forceFetch, _addresses.EntityFactoryToUse, null);
		}

		/// <summary> Retrieves all related entities of type 'AddressesEntity' using a relation of type '1:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <param name="filter">Extra filter to limit the resultset.</param>
		/// <returns>Filled collection with all related entities of type 'AddressesEntity'</returns>
		public OrmSmackdown.LLBLGen.CollectionClasses.AddressesCollection GetMultiAddresses(bool forceFetch, IPredicateExpression filter)
		{
			return GetMultiAddresses(forceFetch, _addresses.EntityFactoryToUse, filter);
		}

		/// <summary> Retrieves all related entities of type 'AddressesEntity' using a relation of type '1:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <param name="entityFactoryToUse">The entity factory to use for the GetMultiManyToOne() routine.</param>
		/// <returns>Filled collection with all related entities of the type constructed by the passed in entity factory</returns>
		public OrmSmackdown.LLBLGen.CollectionClasses.AddressesCollection GetMultiAddresses(bool forceFetch, IEntityFactory entityFactoryToUse)
		{
			return GetMultiAddresses(forceFetch, entityFactoryToUse, null);
		}

		/// <summary> Retrieves all related entities of type 'AddressesEntity' using a relation of type '1:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <param name="entityFactoryToUse">The entity factory to use for the GetMultiManyToOne() routine.</param>
		/// <param name="filter">Extra filter to limit the resultset.</param>
		/// <returns>Filled collection with all related entities of the type constructed by the passed in entity factory</returns>
		public virtual OrmSmackdown.LLBLGen.CollectionClasses.AddressesCollection GetMultiAddresses(bool forceFetch, IEntityFactory entityFactoryToUse, IPredicateExpression filter)
		{
 			if( ( !_alreadyFetchedAddresses || forceFetch || _alwaysFetchAddresses) && !base.IsSerializing && !base.IsDeserializing && !base.InDesignMode)
			{
				if(base.ParticipatesInTransaction)
				{
					if(!_addresses.ParticipatesInTransaction)
					{
						base.Transaction.Add(_addresses);
					}
				}
				_addresses.SuppressClearInGetMulti=!forceFetch;
				if(entityFactoryToUse!=null)
				{
					_addresses.EntityFactoryToUse = entityFactoryToUse;
				}
				_addresses.GetMultiManyToOne(this, filter);
				_addresses.SuppressClearInGetMulti=false;
				_alreadyFetchedAddresses = true;
			}
			return _addresses;
		}

		/// <summary> Sets the collection parameters for the collection for 'Addresses'. These settings will be taken into account
		/// when the property Addresses is requested or GetMultiAddresses is called.</summary>
		/// <param name="maxNumberOfItemsToReturn"> The maximum number of items to return. When set to 0, this parameter is ignored</param>
		/// <param name="sortClauses">The order by specifications for the sorting of the resultset. When not specified (null), no sorting is applied.</param>
		public virtual void SetCollectionParametersAddresses(long maxNumberOfItemsToReturn, ISortExpression sortClauses)
		{
			_addresses.SortClauses=sortClauses;
			_addresses.MaxNumberOfItemsToReturn=maxNumberOfItemsToReturn;
		}

		/// <summary> Retrieves all related entities of type 'PeopleEntity' using a relation of type '1:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <returns>Filled collection with all related entities of type 'PeopleEntity'</returns>
		public OrmSmackdown.LLBLGen.CollectionClasses.PeopleCollection GetMultiManager(bool forceFetch)
		{
			return GetMultiManager(forceFetch, _manager.EntityFactoryToUse, null);
		}

		/// <summary> Retrieves all related entities of type 'PeopleEntity' using a relation of type '1:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <param name="filter">Extra filter to limit the resultset.</param>
		/// <returns>Filled collection with all related entities of type 'PeopleEntity'</returns>
		public OrmSmackdown.LLBLGen.CollectionClasses.PeopleCollection GetMultiManager(bool forceFetch, IPredicateExpression filter)
		{
			return GetMultiManager(forceFetch, _manager.EntityFactoryToUse, filter);
		}

		/// <summary> Retrieves all related entities of type 'PeopleEntity' using a relation of type '1:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <param name="entityFactoryToUse">The entity factory to use for the GetMultiManyToOne() routine.</param>
		/// <returns>Filled collection with all related entities of the type constructed by the passed in entity factory</returns>
		public OrmSmackdown.LLBLGen.CollectionClasses.PeopleCollection GetMultiManager(bool forceFetch, IEntityFactory entityFactoryToUse)
		{
			return GetMultiManager(forceFetch, entityFactoryToUse, null);
		}

		/// <summary> Retrieves all related entities of type 'PeopleEntity' using a relation of type '1:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <param name="entityFactoryToUse">The entity factory to use for the GetMultiManyToOne() routine.</param>
		/// <param name="filter">Extra filter to limit the resultset.</param>
		/// <returns>Filled collection with all related entities of the type constructed by the passed in entity factory</returns>
		public virtual OrmSmackdown.LLBLGen.CollectionClasses.PeopleCollection GetMultiManager(bool forceFetch, IEntityFactory entityFactoryToUse, IPredicateExpression filter)
		{
 			if( ( !_alreadyFetchedManager || forceFetch || _alwaysFetchManager) && !base.IsSerializing && !base.IsDeserializing && !base.InDesignMode)
			{
				if(base.ParticipatesInTransaction)
				{
					if(!_manager.ParticipatesInTransaction)
					{
						base.Transaction.Add(_manager);
					}
				}
				_manager.SuppressClearInGetMulti=!forceFetch;
				if(entityFactoryToUse!=null)
				{
					_manager.EntityFactoryToUse = entityFactoryToUse;
				}
				_manager.GetMultiManyToOne(null, this, null, filter);
				_manager.SuppressClearInGetMulti=false;
				_alreadyFetchedManager = true;
			}
			return _manager;
		}

		/// <summary> Sets the collection parameters for the collection for 'Manager'. These settings will be taken into account
		/// when the property Manager is requested or GetMultiManager is called.</summary>
		/// <param name="maxNumberOfItemsToReturn"> The maximum number of items to return. When set to 0, this parameter is ignored</param>
		/// <param name="sortClauses">The order by specifications for the sorting of the resultset. When not specified (null), no sorting is applied.</param>
		public virtual void SetCollectionParametersManager(long maxNumberOfItemsToReturn, ISortExpression sortClauses)
		{
			_manager.SortClauses=sortClauses;
			_manager.MaxNumberOfItemsToReturn=maxNumberOfItemsToReturn;
		}


		/// <summary> Retrieves all related entities of type 'PortalsEntity' using a relation of type '1:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <returns>Filled collection with all related entities of type 'PortalsEntity'</returns>
		public OrmSmackdown.LLBLGen.CollectionClasses.PortalsCollection GetMultiAdministeredPortals(bool forceFetch)
		{
			return GetMultiAdministeredPortals(forceFetch, _administeredPortals.EntityFactoryToUse, null);
		}

		/// <summary> Retrieves all related entities of type 'PortalsEntity' using a relation of type '1:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <param name="filter">Extra filter to limit the resultset.</param>
		/// <returns>Filled collection with all related entities of type 'PortalsEntity'</returns>
		public OrmSmackdown.LLBLGen.CollectionClasses.PortalsCollection GetMultiAdministeredPortals(bool forceFetch, IPredicateExpression filter)
		{
			return GetMultiAdministeredPortals(forceFetch, _administeredPortals.EntityFactoryToUse, filter);
		}

		/// <summary> Retrieves all related entities of type 'PortalsEntity' using a relation of type '1:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <param name="entityFactoryToUse">The entity factory to use for the GetMultiManyToOne() routine.</param>
		/// <returns>Filled collection with all related entities of the type constructed by the passed in entity factory</returns>
		public OrmSmackdown.LLBLGen.CollectionClasses.PortalsCollection GetMultiAdministeredPortals(bool forceFetch, IEntityFactory entityFactoryToUse)
		{
			return GetMultiAdministeredPortals(forceFetch, entityFactoryToUse, null);
		}

		/// <summary> Retrieves all related entities of type 'PortalsEntity' using a relation of type '1:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <param name="entityFactoryToUse">The entity factory to use for the GetMultiManyToOne() routine.</param>
		/// <param name="filter">Extra filter to limit the resultset.</param>
		/// <returns>Filled collection with all related entities of the type constructed by the passed in entity factory</returns>
		public virtual OrmSmackdown.LLBLGen.CollectionClasses.PortalsCollection GetMultiAdministeredPortals(bool forceFetch, IEntityFactory entityFactoryToUse, IPredicateExpression filter)
		{
 			if( ( !_alreadyFetchedAdministeredPortals || forceFetch || _alwaysFetchAdministeredPortals) && !base.IsSerializing && !base.IsDeserializing && !base.InDesignMode)
			{
				if(base.ParticipatesInTransaction)
				{
					if(!_administeredPortals.ParticipatesInTransaction)
					{
						base.Transaction.Add(_administeredPortals);
					}
				}
				_administeredPortals.SuppressClearInGetMulti=!forceFetch;
				if(entityFactoryToUse!=null)
				{
					_administeredPortals.EntityFactoryToUse = entityFactoryToUse;
				}
				_administeredPortals.GetMultiManyToOne(this, filter);
				_administeredPortals.SuppressClearInGetMulti=false;
				_alreadyFetchedAdministeredPortals = true;
			}
			return _administeredPortals;
		}

		/// <summary> Sets the collection parameters for the collection for 'AdministeredPortals'. These settings will be taken into account
		/// when the property AdministeredPortals is requested or GetMultiAdministeredPortals is called.</summary>
		/// <param name="maxNumberOfItemsToReturn"> The maximum number of items to return. When set to 0, this parameter is ignored</param>
		/// <param name="sortClauses">The order by specifications for the sorting of the resultset. When not specified (null), no sorting is applied.</param>
		public virtual void SetCollectionParametersAdministeredPortals(long maxNumberOfItemsToReturn, ISortExpression sortClauses)
		{
			_administeredPortals.SortClauses=sortClauses;
			_administeredPortals.MaxNumberOfItemsToReturn=maxNumberOfItemsToReturn;
		}


		/// <summary> Retrieves all related entities of type 'PortalsEntity' using a relation of type 'm:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <returns>Filled collection with all related entities of type 'PortalsEntity'</returns>
		public OrmSmackdown.LLBLGen.CollectionClasses.PortalsCollection GetMultiMyPortals(bool forceFetch)
		{
			return GetMultiMyPortals(forceFetch, _myPortals.EntityFactoryToUse);
		}

		/// <summary> Retrieves all related entities of type 'PortalsEntity' using a relation of type 'm:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <param name="entityFactoryToUse">The entity factory to use for the GetMultiManyToMany() routine.</param>
		/// <returns>Filled collection with all related entities of the type constructed by the passed in entity factory</returns>
		public OrmSmackdown.LLBLGen.CollectionClasses.PortalsCollection GetMultiMyPortals(bool forceFetch, IEntityFactory entityFactoryToUse)
		{
 			if( ( !_alreadyFetchedMyPortals || forceFetch || _alwaysFetchMyPortals) && !base.IsSerializing && !base.IsDeserializing && !base.InDesignMode)
			{
				if(base.ParticipatesInTransaction)
				{
					if(!_myPortals.ParticipatesInTransaction)
					{
						base.Transaction.Add(_myPortals);
					}
				}
				IPredicateExpression filter = new PredicateExpression();
				filter.Add(new FieldCompareValuePredicate(PeopleFields.PersonId, ComparisonOperator.Equal, this.PersonId, "PeopleEntity__"));
				_myPortals.SuppressClearInGetMulti=!forceFetch;
				if(entityFactoryToUse!=null)
				{
					_myPortals.EntityFactoryToUse = entityFactoryToUse;
				}
				_myPortals.GetMulti(filter, GetRelationsForField("MyPortals"));
				_myPortals.SuppressClearInGetMulti=false;
				_alreadyFetchedMyPortals = true;
			}
			return _myPortals;
		}

		/// <summary> Sets the collection parameters for the collection for 'MyPortals'. These settings will be taken into account
		/// when the property MyPortals is requested or GetMultiMyPortals is called.</summary>
		/// <param name="maxNumberOfItemsToReturn"> The maximum number of items to return. When set to 0, this parameter is ignored</param>
		/// <param name="sortClauses">The order by specifications for the sorting of the resultset. When not specified (null), no sorting is applied.</param>
		public virtual void SetCollectionParametersMyPortals(long maxNumberOfItemsToReturn, ISortExpression sortClauses)
		{
			_myPortals.SortClauses=sortClauses;
			_myPortals.MaxNumberOfItemsToReturn=maxNumberOfItemsToReturn;
		}


		/// <summary> Retrieves the related entity of type 'CompaniesEntity', using a relation of type 'n:1'</summary>
		/// <returns>A fetched entity of type 'CompaniesEntity' which is related to this entity.</returns>
		public CompaniesEntity GetSingleCompany()
		{
			return GetSingleCompany(false);
		}

		/// <summary> Retrieves the related entity of type 'CompaniesEntity', using a relation of type 'n:1'</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the currently loaded related entity and will refetch the entity from the persistent storage</param>
		/// <returns>A fetched entity of type 'CompaniesEntity' which is related to this entity.</returns>
		public virtual CompaniesEntity GetSingleCompany(bool forceFetch)
		{
			if( ( !_alreadyFetchedCompany || forceFetch || _alwaysFetchCompany) && !base.IsSerializing && !base.IsDeserializing  && !base.InDesignMode)			
			{
				bool performLazyLoading = base.CheckIfLazyLoadingShouldOccur(PeopleEntity.Relations.CompaniesEntityUsingCompanyId);

				CompaniesEntity newEntity = new CompaniesEntity();
				if(base.ParticipatesInTransaction)
				{
					base.Transaction.Add(newEntity);
				}
				bool fetchResult = false;
				if(performLazyLoading)
				{
					fetchResult = newEntity.FetchUsingPK(this.CompanyId.GetValueOrDefault());
				}
				if(fetchResult)
				{
					if(base.ActiveContext!=null)
					{
						newEntity = (CompaniesEntity)base.ActiveContext.Get(newEntity);
					}
					this.Company = newEntity;
				}
				else
				{
					if(_companyReturnsNewIfNotFound)
					{
						if(performLazyLoading || (!performLazyLoading && (_company == null)))
						{
							this.Company = newEntity;
						}
					}
					else
					{
						this.Company = null;
					}
				}
				_alreadyFetchedCompany = fetchResult;
				if(base.ParticipatesInTransaction && !fetchResult)
				{
					base.Transaction.Remove(newEntity);
				}
			}
			return _company;
		}

		/// <summary> Retrieves the related entity of type 'PeopleEntity', using a relation of type 'n:1'</summary>
		/// <returns>A fetched entity of type 'PeopleEntity' which is related to this entity.</returns>
		public PeopleEntity GetSingleEmployees()
		{
			return GetSingleEmployees(false);
		}

		/// <summary> Retrieves the related entity of type 'PeopleEntity', using a relation of type 'n:1'</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the currently loaded related entity and will refetch the entity from the persistent storage</param>
		/// <returns>A fetched entity of type 'PeopleEntity' which is related to this entity.</returns>
		public virtual PeopleEntity GetSingleEmployees(bool forceFetch)
		{
			if( ( !_alreadyFetchedEmployees || forceFetch || _alwaysFetchEmployees) && !base.IsSerializing && !base.IsDeserializing  && !base.InDesignMode)			
			{
				bool performLazyLoading = base.CheckIfLazyLoadingShouldOccur(PeopleEntity.Relations.PeopleEntityUsingPersonIdManagerPersonId);
				// always fetch, even if performLazyLoading is false, because the related entity can be abstract so we can't simply use new. 
				PeopleEntity newEntity = PeopleEntity.FetchPolymorphic(base.Transaction, this.ManagerPersonId.GetValueOrDefault(), base.ActiveContext);
				if(base.ParticipatesInTransaction)
				{
					base.Transaction.Add(newEntity);
				}
				bool fetchResult = (newEntity.Fields.State==EntityState.Fetched);
				if(fetchResult)
				{
					if(base.ActiveContext!=null)
					{
						newEntity = (PeopleEntity)base.ActiveContext.Get(newEntity);
					}
					this.Employees = newEntity;
				}
				else
				{
					if(_employeesReturnsNewIfNotFound)
					{
						if(performLazyLoading || (!performLazyLoading && (_employees == null)))
						{
							this.Employees = newEntity;
						}
					}
					else
					{
						this.Employees = null;
					}
				}
				_alreadyFetchedEmployees = fetchResult;
				if(base.ParticipatesInTransaction && !fetchResult)
				{
					base.Transaction.Remove(newEntity);
				}
			}
			return _employees;
		}

		/// <summary> Retrieves the related entity of type 'RolesEntity', using a relation of type 'n:1'</summary>
		/// <returns>A fetched entity of type 'RolesEntity' which is related to this entity.</returns>
		public RolesEntity GetSingleMyRole()
		{
			return GetSingleMyRole(false);
		}

		/// <summary> Retrieves the related entity of type 'RolesEntity', using a relation of type 'n:1'</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the currently loaded related entity and will refetch the entity from the persistent storage</param>
		/// <returns>A fetched entity of type 'RolesEntity' which is related to this entity.</returns>
		public virtual RolesEntity GetSingleMyRole(bool forceFetch)
		{
			if( ( !_alreadyFetchedMyRole || forceFetch || _alwaysFetchMyRole) && !base.IsSerializing && !base.IsDeserializing  && !base.InDesignMode)			
			{
				bool performLazyLoading = base.CheckIfLazyLoadingShouldOccur(PeopleEntity.Relations.RolesEntityUsingRoleId);

				RolesEntity newEntity = new RolesEntity();
				if(base.ParticipatesInTransaction)
				{
					base.Transaction.Add(newEntity);
				}
				bool fetchResult = false;
				if(performLazyLoading)
				{
					fetchResult = newEntity.FetchUsingPK(this.RoleId);
				}
				if(fetchResult)
				{
					if(base.ActiveContext!=null)
					{
						newEntity = (RolesEntity)base.ActiveContext.Get(newEntity);
					}
					this.MyRole = newEntity;
				}
				else
				{
					if(_myRoleReturnsNewIfNotFound)
					{
						if(performLazyLoading || (!performLazyLoading && (_myRole == null)))
						{
							this.MyRole = newEntity;
						}
					}
					else
					{
						this.MyRole = null;
					}
				}
				_alreadyFetchedMyRole = fetchResult;
				if(base.ParticipatesInTransaction && !fetchResult)
				{
					base.Transaction.Remove(newEntity);
				}
			}
			return _myRole;
		}


		/// <summary> Performs the insert action of a new Entity to the persistent storage.</summary>
		/// <returns>true if succeeded, false otherwise</returns>
		protected override bool InsertEntity()
		{
			PeopleDAO dao = (PeopleDAO)CreateDAOInstance();
			return dao.AddNew(base.Fields, base.Transaction);
		}
		
		/// <summary> Adds the internals to the active context. </summary>
		protected override void AddInternalsToContext()
		{
			_addresses.ActiveContext = base.ActiveContext;
			_manager.ActiveContext = base.ActiveContext;

			_administeredPortals.ActiveContext = base.ActiveContext;

			_myPortals.ActiveContext = base.ActiveContext;

			if(_company!=null)
			{
				_company.ActiveContext = base.ActiveContext;
			}
			if(_employees!=null)
			{
				_employees.ActiveContext = base.ActiveContext;
			}
			if(_myRole!=null)
			{
				_myRole.ActiveContext = base.ActiveContext;
			}


		}


		/// <summary> Performs the update action of an existing Entity to the persistent storage.</summary>
		/// <returns>true if succeeded, false otherwise</returns>
		protected override bool UpdateEntity()
		{
			PeopleDAO dao = (PeopleDAO)CreateDAOInstance();
			return dao.UpdateExisting(base.Fields, base.Transaction);
		}
		
		/// <summary> Performs the update action of an existing Entity to the persistent storage.</summary>
		/// <param name="updateRestriction">Predicate expression, meant for concurrency checks in an Update query</param>
		/// <returns>true if succeeded, false otherwise</returns>
		protected override bool UpdateEntity(IPredicate updateRestriction)
		{
			PeopleDAO dao = (PeopleDAO)CreateDAOInstance();
			return dao.UpdateExisting(base.Fields, base.Transaction, updateRestriction);
		}
	
		/// <summary> Initializes the class with empty data, as if it is a new Entity.</summary>
		/// <param name="validatorToUse">Validator to use.</param>
		protected virtual void InitClassEmpty(IValidator validatorToUse)
		{
			OnInitializing();
			base.Fields = CreateFields();
			base.IsNew=true;
			base.Validator = validatorToUse;
			if(base.Fields.State==EntityState.New)
			{
				base.Fields[(int)PeopleFieldIndex.UserType].ForcedCurrentValueWrite("None");
			}
			InitClassMembers();
			
			// __LLBLGENPRO_USER_CODE_REGION_START InitClassEmpty
			// __LLBLGENPRO_USER_CODE_REGION_END

			OnInitialized();
		}
		
		/// <summary>Creates entity fields object for this entity. Used in constructor to setup this entity in a polymorphic scenario.</summary>
		protected virtual IEntityFields CreateFields()
		{
			return EntityFieldsFactory.CreateEntityFieldsObject(OrmSmackdown.LLBLGen.EntityType.PeopleEntity);
		}
		
		/// <summary>Creates a new transaction object</summary>
		/// <param name="levelOfIsolation">The level of isolation.</param>
		/// <param name="name">The name.</param>
		protected override ITransaction CreateTransaction( IsolationLevel levelOfIsolation, string name )
		{
			return new Transaction(levelOfIsolation, name);
		}

		/// <summary>
		/// Creates the ITypeDefaultValue instance used to provide default values for value types which aren't of type nullable(of T)
		/// </summary>
		/// <returns></returns>
		protected override ITypeDefaultValue CreateTypeDefaultValueProvider()
		{
			return new TypeDefaultValue();
		}

		/// <summary>
		/// Gets all related data objects, stored by name. The name is the field name mapped onto the relation for that particular data element. 
		/// </summary>
		/// <returns>Dictionary with per name the related referenced data element, which can be an entity collection or an entity or null</returns>
		public override Dictionary<string, object> GetRelatedData()
		{
			Dictionary<string, object> toReturn = new Dictionary<string, object>();
			toReturn.Add("Company", _company);
			toReturn.Add("Employees", _employees);
			toReturn.Add("MyRole", _myRole);
			toReturn.Add("Addresses", _addresses);
			toReturn.Add("Manager", _manager);

			toReturn.Add("AdministeredPortals", _administeredPortals);

			toReturn.Add("MyPortals", _myPortals);


			return toReturn;
		}
		

		/// <summary> Initializes the the entity and fetches the data related to the entity in this entity.</summary>
		/// <param name="personId">PK value for People which data should be fetched into this People object</param>
		/// <param name="validator">The validator object for this PeopleEntity</param>
		/// <param name="prefetchPathToUse">the PrefetchPath which defines the graph of objects to fetch as well</param>
		protected virtual void InitClassFetch(System.Int32 personId, IValidator validator, IPrefetchPath prefetchPathToUse)
		{
			OnInitializing();
			base.Validator = validator;
			InitClassMembers();
			base.Fields = CreateFields();
			bool wasSuccesful = Fetch(personId, prefetchPathToUse, null, null);
			base.IsNew = !wasSuccesful;
			if(base.Fields.State==EntityState.New)
			{
				base.Fields[(int)PeopleFieldIndex.UserType].ForcedCurrentValueWrite("None");
			}
			
			// __LLBLGENPRO_USER_CODE_REGION_START InitClassFetch
			// __LLBLGENPRO_USER_CODE_REGION_END

			OnInitialized();
		}

		/// <summary> Initializes the class members</summary>
		private void InitClassMembers()
		{
			_addresses = new OrmSmackdown.LLBLGen.CollectionClasses.AddressesCollection(new AddressesEntityFactory());
			_addresses.SetContainingEntityInfo(this, "Person");
			_alwaysFetchAddresses = false;
			_alreadyFetchedAddresses = false;
			_manager = new OrmSmackdown.LLBLGen.CollectionClasses.PeopleCollection(new PeopleEntityFactory());
			_manager.SetContainingEntityInfo(this, "Employees");
			_alwaysFetchManager = false;
			_alreadyFetchedManager = false;

			_administeredPortals = new OrmSmackdown.LLBLGen.CollectionClasses.PortalsCollection(new PortalsEntityFactory());
			_administeredPortals.SetContainingEntityInfo(this, "AdminUser");
			_alwaysFetchAdministeredPortals = false;
			_alreadyFetchedAdministeredPortals = false;

			_myPortals = new OrmSmackdown.LLBLGen.CollectionClasses.PortalsCollection(new PortalsEntityFactory());
			_alwaysFetchMyPortals = false;
			_alreadyFetchedMyPortals = false;

			_company = null;
			_companyReturnsNewIfNotFound = true;
			_alwaysFetchCompany = false;
			_alreadyFetchedCompany = false;
			_employees = null;
			_employeesReturnsNewIfNotFound = true;
			_alwaysFetchEmployees = false;
			_alreadyFetchedEmployees = false;
			_myRole = null;
			_myRoleReturnsNewIfNotFound = true;
			_alwaysFetchMyRole = false;
			_alreadyFetchedMyRole = false;


			PerformDependencyInjection();
			
			// __LLBLGENPRO_USER_CODE_REGION_START InitClassMembers
			// __LLBLGENPRO_USER_CODE_REGION_END
			OnInitClassMembersComplete();
		}

		#region Custom Property Hashtable Setup
		/// <summary> Initializes the hashtables for the entity type and entity field custom properties. </summary>
		private static void SetupCustomPropertyHashtables()
		{
			_customProperties = new Dictionary<string, string>();
			_fieldsCustomProperties = new Dictionary<string, Dictionary<string, string>>();

			Dictionary<string, string> fieldHashtable = null;
			fieldHashtable = new Dictionary<string, string>();

			_fieldsCustomProperties.Add("PersonId", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();

			_fieldsCustomProperties.Add("FirstName", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();

			_fieldsCustomProperties.Add("LastName", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();

			_fieldsCustomProperties.Add("Email", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();

			_fieldsCustomProperties.Add("CompanyId", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();

			_fieldsCustomProperties.Add("RoleId", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();

			_fieldsCustomProperties.Add("ManagerPersonId", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();

			_fieldsCustomProperties.Add("UserType", fieldHashtable);
		}
		#endregion


		/// <summary> Removes the sync logic for member _company</summary>
		/// <param name="signalRelatedEntity">If set to true, it will call the related entity's UnsetRelatedEntity method</param>
		/// <param name="resetFKFields">if set to true it will also reset the FK fields pointing to the related entity</param>
		private void DesetupSyncCompany(bool signalRelatedEntity, bool resetFKFields)
		{
			base.PerformDesetupSyncRelatedEntity( _company, new PropertyChangedEventHandler( OnCompanyPropertyChanged ), "Company", PeopleEntity.Relations.CompaniesEntityUsingCompanyId, true, signalRelatedEntity, "People", resetFKFields, new int[] { (int)PeopleFieldIndex.CompanyId } );		
			_company = null;
		}
		
		/// <summary> setups the sync logic for member _company</summary>
		/// <param name="relatedEntity">Instance to set as the related entity of type entityType</param>
		private void SetupSyncCompany(IEntity relatedEntity)
		{
			if(_company!=relatedEntity)
			{		
				DesetupSyncCompany(true, true);
				_company = (CompaniesEntity)relatedEntity;
				base.PerformSetupSyncRelatedEntity( _company, new PropertyChangedEventHandler( OnCompanyPropertyChanged ), "Company", PeopleEntity.Relations.CompaniesEntityUsingCompanyId, true, ref _alreadyFetchedCompany, new string[] {  } );
			}
		}

		/// <summary>Handles property change events of properties in a related entity.</summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void OnCompanyPropertyChanged( object sender, PropertyChangedEventArgs e )
		{
			switch( e.PropertyName )
			{
				default:
					break;
			}
		}

		/// <summary> Removes the sync logic for member _employees</summary>
		/// <param name="signalRelatedEntity">If set to true, it will call the related entity's UnsetRelatedEntity method</param>
		/// <param name="resetFKFields">if set to true it will also reset the FK fields pointing to the related entity</param>
		private void DesetupSyncEmployees(bool signalRelatedEntity, bool resetFKFields)
		{
			base.PerformDesetupSyncRelatedEntity( _employees, new PropertyChangedEventHandler( OnEmployeesPropertyChanged ), "Employees", PeopleEntity.Relations.PeopleEntityUsingPersonIdManagerPersonId, true, signalRelatedEntity, "Manager", resetFKFields, new int[] { (int)PeopleFieldIndex.ManagerPersonId } );		
			_employees = null;
		}
		
		/// <summary> setups the sync logic for member _employees</summary>
		/// <param name="relatedEntity">Instance to set as the related entity of type entityType</param>
		private void SetupSyncEmployees(IEntity relatedEntity)
		{
			if(_employees!=relatedEntity)
			{		
				DesetupSyncEmployees(true, true);
				_employees = (PeopleEntity)relatedEntity;
				base.PerformSetupSyncRelatedEntity( _employees, new PropertyChangedEventHandler( OnEmployeesPropertyChanged ), "Employees", PeopleEntity.Relations.PeopleEntityUsingPersonIdManagerPersonId, true, ref _alreadyFetchedEmployees, new string[] {  } );
			}
		}

		/// <summary>Handles property change events of properties in a related entity.</summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void OnEmployeesPropertyChanged( object sender, PropertyChangedEventArgs e )
		{
			switch( e.PropertyName )
			{
				default:
					break;
			}
		}

		/// <summary> Removes the sync logic for member _myRole</summary>
		/// <param name="signalRelatedEntity">If set to true, it will call the related entity's UnsetRelatedEntity method</param>
		/// <param name="resetFKFields">if set to true it will also reset the FK fields pointing to the related entity</param>
		private void DesetupSyncMyRole(bool signalRelatedEntity, bool resetFKFields)
		{
			base.PerformDesetupSyncRelatedEntity( _myRole, new PropertyChangedEventHandler( OnMyRolePropertyChanged ), "MyRole", PeopleEntity.Relations.RolesEntityUsingRoleId, true, signalRelatedEntity, "People", resetFKFields, new int[] { (int)PeopleFieldIndex.RoleId } );		
			_myRole = null;
		}
		
		/// <summary> setups the sync logic for member _myRole</summary>
		/// <param name="relatedEntity">Instance to set as the related entity of type entityType</param>
		private void SetupSyncMyRole(IEntity relatedEntity)
		{
			if(_myRole!=relatedEntity)
			{		
				DesetupSyncMyRole(true, true);
				_myRole = (RolesEntity)relatedEntity;
				base.PerformSetupSyncRelatedEntity( _myRole, new PropertyChangedEventHandler( OnMyRolePropertyChanged ), "MyRole", PeopleEntity.Relations.RolesEntityUsingRoleId, true, ref _alreadyFetchedMyRole, new string[] {  } );
			}
		}

		/// <summary>Handles property change events of properties in a related entity.</summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void OnMyRolePropertyChanged( object sender, PropertyChangedEventArgs e )
		{
			switch( e.PropertyName )
			{
				default:
					break;
			}
		}


		/// <summary> Fetches the entity from the persistent storage. Fetch simply reads the entity into an EntityFields object. </summary>
		/// <param name="personId">PK value for People which data should be fetched into this People object</param>
		/// <param name="prefetchPathToUse">the PrefetchPath which defines the graph of objects to fetch as well</param>
		/// <param name="contextToUse">The context to add the entity to if the fetch was succesful. </param>
		/// <param name="excludedIncludedFields">The list of IEntityField objects which have to be excluded or included for the fetch. 
		/// If null or empty, all fields are fetched (default). If an instance of ExcludeIncludeFieldsList is passed in and its ExcludeContainedFields property
		/// is set to false, the fields contained in excludedIncludedFields are kept in the query, the rest of the fields in the query are excluded.</param>
		/// <returns>True if succeeded, false otherwise.</returns>
		private bool Fetch(System.Int32 personId, IPrefetchPath prefetchPathToUse, Context contextToUse, ExcludeIncludeFieldsList excludedIncludedFields)
		{
			try
			{
				OnFetch();
				IDao dao = this.CreateDAOInstance();
				base.Fields[(int)PeopleFieldIndex.PersonId].ForcedCurrentValueWrite(personId);
				dao.FetchExisting(this, base.Transaction, prefetchPathToUse, contextToUse, excludedIncludedFields);
				return (base.Fields.State == EntityState.Fetched);
			}
			finally
			{
				OnFetchComplete();
			}
		}


		/// <summary> Creates the DAO instance for this type</summary>
		/// <returns></returns>
		protected override IDao CreateDAOInstance()
		{
			return DAOFactory.CreatePeopleDAO();
		}
		
		/// <summary> Creates the entity factory for this type.</summary>
		/// <returns></returns>
		protected override IEntityFactory CreateEntityFactory()
		{
			return new PeopleEntityFactory();
		}

		#region Class Property Declarations
		/// <summary> The relations object holding all relations of this entity with other entity classes.</summary>
		public  static PeopleRelations Relations
		{
			get	{ return new PeopleRelations(); }
		}
		
		/// <summary> The custom properties for this entity type.</summary>
		/// <remarks>The data returned from this property should be considered read-only: it is not thread safe to alter this data at runtime.</remarks>
		public  static Dictionary<string, string> CustomProperties
		{
			get { return _customProperties;}
		}


		/// <summary> Creates a new PrefetchPathElement object which contains all the information to prefetch the related entities of type 'Addresses' 
		/// for this entity. Add the object returned by this property to an existing PrefetchPath instance.</summary>
		/// <returns>Ready to use IPrefetchPathElement implementation.</returns>
		public static IPrefetchPathElement PrefetchPathAddresses
		{
			get
			{
				return new PrefetchPathElement(new OrmSmackdown.LLBLGen.CollectionClasses.AddressesCollection(),
					(IEntityRelation)GetRelationsForField("Addresses")[0], (int)OrmSmackdown.LLBLGen.EntityType.PeopleEntity, (int)OrmSmackdown.LLBLGen.EntityType.AddressesEntity, 0, null, null, null, "Addresses", SD.LLBLGen.Pro.ORMSupportClasses.RelationType.OneToMany);
			}
		}

		/// <summary> Creates a new PrefetchPathElement object which contains all the information to prefetch the related entities of type 'People' 
		/// for this entity. Add the object returned by this property to an existing PrefetchPath instance.</summary>
		/// <returns>Ready to use IPrefetchPathElement implementation.</returns>
		public static IPrefetchPathElement PrefetchPathManager
		{
			get
			{
				return new PrefetchPathElement(new OrmSmackdown.LLBLGen.CollectionClasses.PeopleCollection(),
					(IEntityRelation)GetRelationsForField("Manager")[0], (int)OrmSmackdown.LLBLGen.EntityType.PeopleEntity, (int)OrmSmackdown.LLBLGen.EntityType.PeopleEntity, 0, null, null, null, "Manager", SD.LLBLGen.Pro.ORMSupportClasses.RelationType.OneToMany);
			}
		}


		/// <summary> Creates a new PrefetchPathElement object which contains all the information to prefetch the related entities of type 'Portals' 
		/// for this entity. Add the object returned by this property to an existing PrefetchPath instance.</summary>
		/// <returns>Ready to use IPrefetchPathElement implementation.</returns>
		public static IPrefetchPathElement PrefetchPathAdministeredPortals
		{
			get
			{
				return new PrefetchPathElement(new OrmSmackdown.LLBLGen.CollectionClasses.PortalsCollection(),
					(IEntityRelation)GetRelationsForField("AdministeredPortals")[0], (int)OrmSmackdown.LLBLGen.EntityType.PeopleEntity, (int)OrmSmackdown.LLBLGen.EntityType.PortalsEntity, 0, null, null, null, "AdministeredPortals", SD.LLBLGen.Pro.ORMSupportClasses.RelationType.OneToMany);
			}
		}


		/// <summary> Creates a new PrefetchPathElement object which contains all the information to prefetch the related entities of type 'Portals' 
		/// for this entity. Add the object returned by this property to an existing PrefetchPath instance.</summary>
		/// <returns>Ready to use IPrefetchPathElement implementation.</returns>
		public static IPrefetchPathElement PrefetchPathMyPortals
		{
			get
			{
				IEntityRelation intermediateRelation = PeopleEntity.Relations.PortalPeopleXrefEntityUsingPersonId;
				intermediateRelation.SetAliases(string.Empty, "PortalPeopleXref_");
				return new PrefetchPathElement(new OrmSmackdown.LLBLGen.CollectionClasses.PortalsCollection(), intermediateRelation,
					(int)OrmSmackdown.LLBLGen.EntityType.PeopleEntity, (int)OrmSmackdown.LLBLGen.EntityType.PortalsEntity, 0, null, null, GetRelationsForField("MyPortals"), "MyPortals", SD.LLBLGen.Pro.ORMSupportClasses.RelationType.ManyToMany);
			}
		}


		/// <summary> Creates a new PrefetchPathElement object which contains all the information to prefetch the related entities of type 'Companies' 
		/// for this entity. Add the object returned by this property to an existing PrefetchPath instance.</summary>
		/// <returns>Ready to use IPrefetchPathElement implementation.</returns>
		public static IPrefetchPathElement PrefetchPathCompany
		{
			get
			{
				return new PrefetchPathElement(new OrmSmackdown.LLBLGen.CollectionClasses.CompaniesCollection(),
					(IEntityRelation)GetRelationsForField("Company")[0], (int)OrmSmackdown.LLBLGen.EntityType.PeopleEntity, (int)OrmSmackdown.LLBLGen.EntityType.CompaniesEntity, 0, null, null, null, "Company", SD.LLBLGen.Pro.ORMSupportClasses.RelationType.ManyToOne);
			}
		}

		/// <summary> Creates a new PrefetchPathElement object which contains all the information to prefetch the related entities of type 'People' 
		/// for this entity. Add the object returned by this property to an existing PrefetchPath instance.</summary>
		/// <returns>Ready to use IPrefetchPathElement implementation.</returns>
		public static IPrefetchPathElement PrefetchPathEmployees
		{
			get
			{
				return new PrefetchPathElement(new OrmSmackdown.LLBLGen.CollectionClasses.PeopleCollection(),
					(IEntityRelation)GetRelationsForField("Employees")[0], (int)OrmSmackdown.LLBLGen.EntityType.PeopleEntity, (int)OrmSmackdown.LLBLGen.EntityType.PeopleEntity, 0, null, null, null, "Employees", SD.LLBLGen.Pro.ORMSupportClasses.RelationType.ManyToOne);
			}
		}

		/// <summary> Creates a new PrefetchPathElement object which contains all the information to prefetch the related entities of type 'Roles' 
		/// for this entity. Add the object returned by this property to an existing PrefetchPath instance.</summary>
		/// <returns>Ready to use IPrefetchPathElement implementation.</returns>
		public static IPrefetchPathElement PrefetchPathMyRole
		{
			get
			{
				return new PrefetchPathElement(new OrmSmackdown.LLBLGen.CollectionClasses.RolesCollection(),
					(IEntityRelation)GetRelationsForField("MyRole")[0], (int)OrmSmackdown.LLBLGen.EntityType.PeopleEntity, (int)OrmSmackdown.LLBLGen.EntityType.RolesEntity, 0, null, null, null, "MyRole", SD.LLBLGen.Pro.ORMSupportClasses.RelationType.ManyToOne);
			}
		}


		/// <summary>Returns the full name for this entity, which is important for the DAO to find back persistence info for this entity.</summary>
		[Browsable(false), XmlIgnore]
		public override string LLBLGenProEntityName
		{
			get { return "PeopleEntity";}
		}

		/// <summary> The custom properties for the type of this entity instance.</summary>
		/// <remarks>The data returned from this property should be considered read-only: it is not thread safe to alter this data at runtime.</remarks>
		[Browsable(false), XmlIgnore]
		public override Dictionary<string, string> CustomPropertiesOfType
		{
			get { return PeopleEntity.CustomProperties;}
		}

		/// <summary> The custom properties for the fields of this entity type. The returned Hashtable contains per fieldname a hashtable of name-value pairs. </summary>
		/// <remarks>The data returned from this property should be considered read-only: it is not thread safe to alter this data at runtime.</remarks>
		public  static Dictionary<string, Dictionary<string, string>> FieldsCustomProperties
		{
			get { return _fieldsCustomProperties;}
		}

		/// <summary> The custom properties for the fields of the type of this entity instance. The returned Hashtable contains per fieldname a hashtable of name-value pairs. </summary>
		/// <remarks>The data returned from this property should be considered read-only: it is not thread safe to alter this data at runtime.</remarks>
		[Browsable(false), XmlIgnore]
		public override Dictionary<string, Dictionary<string, string>> FieldsCustomPropertiesOfType
		{
			get { return PeopleEntity.FieldsCustomProperties;}
		}

		/// <summary> The PersonId property of the Entity People<br/><br/>
		/// </summary>
		/// <remarks>Mapped on  table field: "People"."PersonId"<br/>
		/// Table field type characteristics (type, precision, scale, length): Int, 10, 0, 0<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): false, true, true</remarks>
		public virtual System.Int32 PersonId
		{
			get { return (System.Int32)GetValue((int)PeopleFieldIndex.PersonId, true); }
			set	{ SetValue((int)PeopleFieldIndex.PersonId, value, true); }
		}
		/// <summary> The FirstName property of the Entity People<br/><br/>
		/// </summary>
		/// <remarks>Mapped on  table field: "People"."FirstName"<br/>
		/// Table field type characteristics (type, precision, scale, length): VarChar, 0, 0, 50<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): false, false, false</remarks>
		public virtual System.String FirstName
		{
			get { return (System.String)GetValue((int)PeopleFieldIndex.FirstName, true); }
			set	{ SetValue((int)PeopleFieldIndex.FirstName, value, true); }
		}
		/// <summary> The LastName property of the Entity People<br/><br/>
		/// </summary>
		/// <remarks>Mapped on  table field: "People"."LastName"<br/>
		/// Table field type characteristics (type, precision, scale, length): VarChar, 0, 0, 50<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): false, false, false</remarks>
		public virtual System.String LastName
		{
			get { return (System.String)GetValue((int)PeopleFieldIndex.LastName, true); }
			set	{ SetValue((int)PeopleFieldIndex.LastName, value, true); }
		}
		/// <summary> The Email property of the Entity People<br/><br/>
		/// </summary>
		/// <remarks>Mapped on  table field: "People"."Email"<br/>
		/// Table field type characteristics (type, precision, scale, length): VarChar, 0, 0, 128<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): false, false, false</remarks>
		public virtual System.String Email
		{
			get { return (System.String)GetValue((int)PeopleFieldIndex.Email, true); }
			set	{ SetValue((int)PeopleFieldIndex.Email, value, true); }
		}
		/// <summary> The CompanyId property of the Entity People<br/><br/>
		/// </summary>
		/// <remarks>Mapped on  table field: "People"."CompanyId"<br/>
		/// Table field type characteristics (type, precision, scale, length): Int, 10, 0, 0<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): true, false, false</remarks>
		public virtual Nullable<System.Int32> CompanyId
		{
			get { return (Nullable<System.Int32>)GetValue((int)PeopleFieldIndex.CompanyId, false); }
			set	{ SetValue((int)PeopleFieldIndex.CompanyId, value, true); }
		}
		/// <summary> The RoleId property of the Entity People<br/><br/>
		/// </summary>
		/// <remarks>Mapped on  table field: "People"."RoleId"<br/>
		/// Table field type characteristics (type, precision, scale, length): Int, 10, 0, 0<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): false, false, false</remarks>
		public virtual System.Int32 RoleId
		{
			get { return (System.Int32)GetValue((int)PeopleFieldIndex.RoleId, true); }
			set	{ SetValue((int)PeopleFieldIndex.RoleId, value, true); }
		}
		/// <summary> The ManagerPersonId property of the Entity People<br/><br/>
		/// </summary>
		/// <remarks>Mapped on  table field: "People"."ManagerPersonId"<br/>
		/// Table field type characteristics (type, precision, scale, length): Int, 10, 0, 0<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): true, false, false</remarks>
		public virtual Nullable<System.Int32> ManagerPersonId
		{
			get { return (Nullable<System.Int32>)GetValue((int)PeopleFieldIndex.ManagerPersonId, false); }
			set	{ SetValue((int)PeopleFieldIndex.ManagerPersonId, value, true); }
		}
		/// <summary> The UserType property of the Entity People<br/><br/>
		/// </summary>
		/// <remarks>Mapped on  table field: "People"."UserType"<br/>
		/// Table field type characteristics (type, precision, scale, length): Char, 0, 0, 2<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): false, false, false</remarks>
		public virtual System.String UserType
		{
			get { return (System.String)GetValue((int)PeopleFieldIndex.UserType, true); }

		}

		/// <summary> Retrieves all related entities of type 'AddressesEntity' using a relation of type '1:n'.</summary>
		/// <remarks>This property is added for databinding conveniance, however it is recommeded to use the method 'GetMultiAddresses()', because 
		/// this property is rather expensive and a method tells the user to cache the result when it has to be used more than once in the same scope.</remarks>
		public virtual OrmSmackdown.LLBLGen.CollectionClasses.AddressesCollection Addresses
		{
			get	{ return GetMultiAddresses(false); }
		}

		/// <summary> Gets / sets the lazy loading flag for Addresses. When set to true, Addresses is always refetched from the 
		/// persistent storage. When set to false, the data is only fetched the first time Addresses is accessed. You can always execute
		/// a forced fetch by calling GetMultiAddresses(true).</summary>
		[Browsable(false)]
		public bool AlwaysFetchAddresses
		{
			get	{ return _alwaysFetchAddresses; }
			set	{ _alwaysFetchAddresses = value; }	
		}		
				
		/// <summary>Gets / Sets the lazy loading flag if the property Addresses already has been fetched. Setting this property to false when Addresses has been fetched
		/// will clear the Addresses collection well. Setting this property to true while Addresses hasn't been fetched disables lazy loading for Addresses</summary>
		[Browsable(false)]
		public bool AlreadyFetchedAddresses
		{
			get { return _alreadyFetchedAddresses;}
			set 
			{
				if(_alreadyFetchedAddresses && !value && (_addresses != null))
				{
					_addresses.Clear();
				}
				_alreadyFetchedAddresses = value;
			}
		}
		/// <summary> Retrieves all related entities of type 'PeopleEntity' using a relation of type '1:n'.</summary>
		/// <remarks>This property is added for databinding conveniance, however it is recommeded to use the method 'GetMultiManager()', because 
		/// this property is rather expensive and a method tells the user to cache the result when it has to be used more than once in the same scope.</remarks>
		public virtual OrmSmackdown.LLBLGen.CollectionClasses.PeopleCollection Manager
		{
			get	{ return GetMultiManager(false); }
		}

		/// <summary> Gets / sets the lazy loading flag for Manager. When set to true, Manager is always refetched from the 
		/// persistent storage. When set to false, the data is only fetched the first time Manager is accessed. You can always execute
		/// a forced fetch by calling GetMultiManager(true).</summary>
		[Browsable(false)]
		public bool AlwaysFetchManager
		{
			get	{ return _alwaysFetchManager; }
			set	{ _alwaysFetchManager = value; }	
		}		
				
		/// <summary>Gets / Sets the lazy loading flag if the property Manager already has been fetched. Setting this property to false when Manager has been fetched
		/// will clear the Manager collection well. Setting this property to true while Manager hasn't been fetched disables lazy loading for Manager</summary>
		[Browsable(false)]
		public bool AlreadyFetchedManager
		{
			get { return _alreadyFetchedManager;}
			set 
			{
				if(_alreadyFetchedManager && !value && (_manager != null))
				{
					_manager.Clear();
				}
				_alreadyFetchedManager = value;
			}
		}
		/// <summary> Retrieves all related entities of type 'PortalsEntity' using a relation of type '1:n'.</summary>
		/// <remarks>This property is added for databinding conveniance, however it is recommeded to use the method 'GetMultiAdministeredPortals()', because 
		/// this property is rather expensive and a method tells the user to cache the result when it has to be used more than once in the same scope.</remarks>
		public virtual OrmSmackdown.LLBLGen.CollectionClasses.PortalsCollection AdministeredPortals
		{
			get	{ return GetMultiAdministeredPortals(false); }
		}

		/// <summary> Gets / sets the lazy loading flag for AdministeredPortals. When set to true, AdministeredPortals is always refetched from the 
		/// persistent storage. When set to false, the data is only fetched the first time AdministeredPortals is accessed. You can always execute
		/// a forced fetch by calling GetMultiAdministeredPortals(true).</summary>
		[Browsable(false)]
		public bool AlwaysFetchAdministeredPortals
		{
			get	{ return _alwaysFetchAdministeredPortals; }
			set	{ _alwaysFetchAdministeredPortals = value; }	
		}		
				
		/// <summary>Gets / Sets the lazy loading flag if the property AdministeredPortals already has been fetched. Setting this property to false when AdministeredPortals has been fetched
		/// will clear the AdministeredPortals collection well. Setting this property to true while AdministeredPortals hasn't been fetched disables lazy loading for AdministeredPortals</summary>
		[Browsable(false)]
		public bool AlreadyFetchedAdministeredPortals
		{
			get { return _alreadyFetchedAdministeredPortals;}
			set 
			{
				if(_alreadyFetchedAdministeredPortals && !value && (_administeredPortals != null))
				{
					_administeredPortals.Clear();
				}
				_alreadyFetchedAdministeredPortals = value;
			}
		}

		/// <summary> Retrieves all related entities of type 'PortalsEntity' using a relation of type 'm:n'.</summary>
		/// <remarks>This property is added for databinding conveniance, however it is recommeded to use the method 'GetMultiMyPortals()', because 
		/// this property is rather expensive and a method tells the user to cache the result when it has to be used more than once in the same scope.</remarks>
		public virtual OrmSmackdown.LLBLGen.CollectionClasses.PortalsCollection MyPortals
		{
			get { return GetMultiMyPortals(false); }
		}

		/// <summary> Gets / sets the lazy loading flag for MyPortals. When set to true, MyPortals is always refetched from the 
		/// persistent storage. When set to false, the data is only fetched the first time MyPortals is accessed. You can always execute
		/// a forced fetch by calling GetMultiMyPortals(true).</summary>
		[Browsable(false)]
		public bool AlwaysFetchMyPortals
		{
			get	{ return _alwaysFetchMyPortals; }
			set	{ _alwaysFetchMyPortals = value; }
		}
				
		/// <summary>Gets / Sets the lazy loading flag if the property MyPortals already has been fetched. Setting this property to false when MyPortals has been fetched
		/// will clear the MyPortals collection well. Setting this property to true while MyPortals hasn't been fetched disables lazy loading for MyPortals</summary>
		[Browsable(false)]
		public bool AlreadyFetchedMyPortals
		{
			get { return _alreadyFetchedMyPortals;}
			set 
			{
				if(_alreadyFetchedMyPortals && !value && (_myPortals != null))
				{
					_myPortals.Clear();
				}
				_alreadyFetchedMyPortals = value;
			}
		}

		/// <summary> Gets / sets related entity of type 'CompaniesEntity'. This property is not visible in databound grids.
		/// Setting this property to a new object will make the load-on-demand feature to stop fetching data from the database, until you set this
		/// property to null. Setting this property to an entity will make sure that FK-PK relations are synchronized when appropriate.</summary>
		/// <remarks>This property is added for conveniance, however it is recommeded to use the method 'GetSingleCompany()', because 
		/// this property is rather expensive and a method tells the user to cache the result when it has to be used more than once in the
		/// same scope. The property is marked non-browsable to make it hidden in bound controls, f.e. datagrids.</remarks>
		[Browsable(false)]
		public virtual CompaniesEntity Company
		{
			get	{ return GetSingleCompany(false); }
			set
			{
				if(base.IsDeserializing)
				{
					SetupSyncCompany(value);
				}
				else
				{
					if(value==null)
					{
						if(_company != null)
						{
							_company.UnsetRelatedEntity(this, "People");
						}
					}
					else
					{
						if(_company!=value)
						{
							((IEntity)value).SetRelatedEntity(this, "People");
						}
					}
				}
			}
		}

		/// <summary> Gets / sets the lazy loading flag for Company. When set to true, Company is always refetched from the 
		/// persistent storage. When set to false, the data is only fetched the first time Company is accessed. You can always execute
		/// a forced fetch by calling GetSingleCompany(true).</summary>
		[Browsable(false)]
		public bool AlwaysFetchCompany
		{
			get	{ return _alwaysFetchCompany; }
			set	{ _alwaysFetchCompany = value; }	
		}
				
		/// <summary>Gets / Sets the lazy loading flag if the property Company already has been fetched. Setting this property to false when Company has been fetched
		/// will set Company to null as well. Setting this property to true while Company hasn't been fetched disables lazy loading for Company</summary>
		[Browsable(false)]
		public bool AlreadyFetchedCompany
		{
			get { return _alreadyFetchedCompany;}
			set 
			{
				if(_alreadyFetchedCompany && !value)
				{
					this.Company = null;
				}
				_alreadyFetchedCompany = value;
			}
		}

		/// <summary> Gets / sets the flag for what to do if the related entity available through the property Company is not found
		/// in the database. When set to true, Company will return a new entity instance if the related entity is not found, otherwise 
		/// null be returned if the related entity is not found. Default: true.</summary>
		[Browsable(false)]
		public bool CompanyReturnsNewIfNotFound
		{
			get	{ return _companyReturnsNewIfNotFound; }
			set { _companyReturnsNewIfNotFound = value; }	
		}
		/// <summary> Gets / sets related entity of type 'PeopleEntity'. This property is not visible in databound grids.
		/// Setting this property to a new object will make the load-on-demand feature to stop fetching data from the database, until you set this
		/// property to null. Setting this property to an entity will make sure that FK-PK relations are synchronized when appropriate.</summary>
		/// <remarks>This property is added for conveniance, however it is recommeded to use the method 'GetSingleEmployees()', because 
		/// this property is rather expensive and a method tells the user to cache the result when it has to be used more than once in the
		/// same scope. The property is marked non-browsable to make it hidden in bound controls, f.e. datagrids.</remarks>
		[Browsable(false)]
		public virtual PeopleEntity Employees
		{
			get	{ return GetSingleEmployees(false); }
			set
			{
				if(base.IsDeserializing)
				{
					SetupSyncEmployees(value);
				}
				else
				{
					if(value==null)
					{
						if(_employees != null)
						{
							_employees.UnsetRelatedEntity(this, "Manager");
						}
					}
					else
					{
						if(_employees!=value)
						{
							((IEntity)value).SetRelatedEntity(this, "Manager");
						}
					}
				}
			}
		}

		/// <summary> Gets / sets the lazy loading flag for Employees. When set to true, Employees is always refetched from the 
		/// persistent storage. When set to false, the data is only fetched the first time Employees is accessed. You can always execute
		/// a forced fetch by calling GetSingleEmployees(true).</summary>
		[Browsable(false)]
		public bool AlwaysFetchEmployees
		{
			get	{ return _alwaysFetchEmployees; }
			set	{ _alwaysFetchEmployees = value; }	
		}
				
		/// <summary>Gets / Sets the lazy loading flag if the property Employees already has been fetched. Setting this property to false when Employees has been fetched
		/// will set Employees to null as well. Setting this property to true while Employees hasn't been fetched disables lazy loading for Employees</summary>
		[Browsable(false)]
		public bool AlreadyFetchedEmployees
		{
			get { return _alreadyFetchedEmployees;}
			set 
			{
				if(_alreadyFetchedEmployees && !value)
				{
					this.Employees = null;
				}
				_alreadyFetchedEmployees = value;
			}
		}

		/// <summary> Gets / sets the flag for what to do if the related entity available through the property Employees is not found
		/// in the database. When set to true, Employees will return a new entity instance if the related entity is not found, otherwise 
		/// null be returned if the related entity is not found. Default: true.</summary>
		[Browsable(false)]
		public bool EmployeesReturnsNewIfNotFound
		{
			get	{ return _employeesReturnsNewIfNotFound; }
			set { _employeesReturnsNewIfNotFound = value; }	
		}
		/// <summary> Gets / sets related entity of type 'RolesEntity'. This property is not visible in databound grids.
		/// Setting this property to a new object will make the load-on-demand feature to stop fetching data from the database, until you set this
		/// property to null. Setting this property to an entity will make sure that FK-PK relations are synchronized when appropriate.</summary>
		/// <remarks>This property is added for conveniance, however it is recommeded to use the method 'GetSingleMyRole()', because 
		/// this property is rather expensive and a method tells the user to cache the result when it has to be used more than once in the
		/// same scope. The property is marked non-browsable to make it hidden in bound controls, f.e. datagrids.</remarks>
		[Browsable(false)]
		public virtual RolesEntity MyRole
		{
			get	{ return GetSingleMyRole(false); }
			set
			{
				if(base.IsDeserializing)
				{
					SetupSyncMyRole(value);
				}
				else
				{
					if(value==null)
					{
						if(_myRole != null)
						{
							_myRole.UnsetRelatedEntity(this, "People");
						}
					}
					else
					{
						if(_myRole!=value)
						{
							((IEntity)value).SetRelatedEntity(this, "People");
						}
					}
				}
			}
		}

		/// <summary> Gets / sets the lazy loading flag for MyRole. When set to true, MyRole is always refetched from the 
		/// persistent storage. When set to false, the data is only fetched the first time MyRole is accessed. You can always execute
		/// a forced fetch by calling GetSingleMyRole(true).</summary>
		[Browsable(false)]
		public bool AlwaysFetchMyRole
		{
			get	{ return _alwaysFetchMyRole; }
			set	{ _alwaysFetchMyRole = value; }	
		}
				
		/// <summary>Gets / Sets the lazy loading flag if the property MyRole already has been fetched. Setting this property to false when MyRole has been fetched
		/// will set MyRole to null as well. Setting this property to true while MyRole hasn't been fetched disables lazy loading for MyRole</summary>
		[Browsable(false)]
		public bool AlreadyFetchedMyRole
		{
			get { return _alreadyFetchedMyRole;}
			set 
			{
				if(_alreadyFetchedMyRole && !value)
				{
					this.MyRole = null;
				}
				_alreadyFetchedMyRole = value;
			}
		}

		/// <summary> Gets / sets the flag for what to do if the related entity available through the property MyRole is not found
		/// in the database. When set to true, MyRole will return a new entity instance if the related entity is not found, otherwise 
		/// null be returned if the related entity is not found. Default: true.</summary>
		[Browsable(false)]
		public bool MyRoleReturnsNewIfNotFound
		{
			get	{ return _myRoleReturnsNewIfNotFound; }
			set { _myRoleReturnsNewIfNotFound = value; }	
		}



		/// <summary> Gets or sets a value indicating whether this entity is a subtype</summary>
		protected override bool LLBLGenProIsSubType
		{
			get { return false;}
		}

		/// <summary> Gets the type of the hierarchy this entity is in. </summary>
		[System.ComponentModel.Browsable(false), XmlIgnore]
		protected override InheritanceHierarchyType LLBLGenProIsInHierarchyOfType
		{
			get { return InheritanceHierarchyType.TargetPerEntityHierarchy;}
		}
		
		/// <summary>Returns the OrmSmackdown.LLBLGen.EntityType enum value for this entity.</summary>
		[Browsable(false), XmlIgnore]
		public override int LLBLGenProEntityTypeValue 
		{ 
			get { return (int)OrmSmackdown.LLBLGen.EntityType.PeopleEntity; }
		}
		#endregion


		#region Custom Entity code
		
		// __LLBLGENPRO_USER_CODE_REGION_START CustomEntityCode
		// __LLBLGENPRO_USER_CODE_REGION_END
		#endregion

		#region Included code

		#endregion
	}
}
